package controllers

import (
	"fmt"
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/facades"
	"goravel/app/models"
)

type SocketController struct {
	//Dependent services
}

func NewSocketController() *SocketController {
	return &SocketController{
		//Inject services
	}
}

func (r *SocketController) Cache(ctx http.Context) http.Response {
	clientId := ctx.Request().Input("clientId")
	var user models.User
	facades.Auth(ctx).User(&user) // 必须是指针
	facades.Cache().Put(fmt.Sprintf("user:%d", user.ID), clientId, 0)
	return ctx.Response().Success().Json(http.Json{
		"message": "连接成功",
	})
}
